package com.wyj.server;

import com.wyj.mapper.MappedContext;
import com.wyj.mapper.MappedHost;

import java.util.List;

/**
 * TODO: 虚拟主机。一个engine可以有多个虚拟主机。
 *
 * @author wuyijie
 * @date 2021/12/13 22:02
 */
public class Host extends BaseLiflecycleBean {
    private String name;
    private String appBase;


    private List<Context> contextList;

    public Host() {
    }

    public Host(String name, String appBase) {
        this.name = name;
        this.appBase = appBase;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getAppBase() {
        return appBase;
    }

    public void setAppBase(String appBase) {
        this.appBase = appBase;
    }

    public List<Context> getContextList() {
        return contextList;
    }

    public void setContextList(List<Context> contextList) {
        this.contextList = contextList;
    }

    @Override
    public String toString() {
        return "Host{" +
                "name='" + name + '\'' +
                ", appBase='" + appBase + '\'' +
                ", contextList=" + contextList +
                '}';
    }

    @Override
    public void init() {
        MappedHost mappedHost = new MappedHost();

        if (null != this.contextList && this.contextList.size() > 0) {
            for (Context context : this.contextList) {
                mappedHost.getMappedContextMap().put(context.getPath(),new MappedContext(context));
            }
        }
        Digester.MAPPER.getMappedHostMap().put(this.name,mappedHost);
        System.out.println(Digester.MAPPER);

    }

    @Override
    public void start() {

    }
}
